/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.scm.hibernate.entities;

import com.scm.hibernate.utilities.HibernateUtil;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author Sony
 */
@Table(name = "students")
@Entity
public class Student extends AbstractEntity {

    public static ArrayList<Object> page(List<Object> li_exam) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Id
    @GeneratedValue
    @Column(name = "id")
    protected Long id;
    @Column(name = "addedby")
    protected Long addedby;
    @Column(name = "divid")
    protected Long divid;
    @Column(name = "fname")
    protected String fname;
    @Column(name = "mname")
    protected String mname;
    @Column(name = "lname")
    protected String lname;
    @Column(name = "gender")
    protected String gender;
    @Column(name = "email")
    protected String email;
    @Column(name = "password")
    protected String password;
    @Column(name = "address")
    protected String address;
    @Column(name = "city")
    protected String city;
    @Column(name = "s_state")
    protected String s_state;
    @Column(name = "religion")
    protected String religion;
    @Column(name = "s_cast")
    protected String s_cast;
    @Column(name = "category")
    protected String category;
    @Column(name = "contact")
    protected String contact;
    @Column(name = "enrollmentno")
    protected String enrollmentno;
    @Column(name = "dateofbirth")
    protected String dateofbirth;

    @Column(name = "physicallyhandicapped")
    protected boolean physicallyhandicapped;
    @Column(name = "status")
    protected boolean status;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getAddedby() {
        return addedby;
    }

    public void setAddedby(Long addedby) {
        this.addedby = addedby;
    }

    public Long getDivid() {
        return divid;
    }

    public void setDivid(Long divid) {
        this.divid = divid;
    }

    public String getFname() {
        return fname;
    }

    public void setFname(String fname) {
        this.fname = fname;
    }

    public String getMname() {
        return mname;
    }

    public void setMname(String mname) {
        this.mname = mname;
    }

    public String getLname() {
        return lname;
    }

    public void setLname(String lname) {
        this.lname = lname;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getS_state() {
        return s_state;
    }

    public void setS_state(String s_state) {
        this.s_state = s_state;
    }

    public String getReligion() {
        return religion;
    }

    public void setReligion(String religion) {
        this.religion = religion;
    }

    public String getS_cast() {
        return s_cast;
    }

    public void setS_cast(String s_cast) {
        this.s_cast = s_cast;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getContact() {
        return contact;
    }

    public void setContact(String contact) {
        this.contact = contact;
    }

    public String getEnrollmentno() {
        return enrollmentno;
    }

    public void setEnrollmentno(String enrollmentno) {
        this.enrollmentno = enrollmentno;
    }

    public String getDateofbirth() {
        return dateofbirth;
    }

    public void setDateofbirth(String dateofbirth) {
        this.dateofbirth = dateofbirth;
    }

    public boolean isPhysicallyhandicapped() {
        return physicallyhandicapped;
    }

    public void setPhysicallyhandicapped(boolean physicallyhandicapped) {
        this.physicallyhandicapped = physicallyhandicapped;
    }

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public Student verify() {
        Student s = null;
        try {
            Session ss = HibernateUtil.getSessionFactory().openSession();
            Query q = ss.createQuery("from Student where email='" + this.email + "' and password='" + this.password + "'");

            List<Student> li = q.list();

            if (li.size() == 1) {
                s = li.get(0);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return s;
    }

    public static List<Student> getallstudents() {
        List<Student> li = null;
        try {
            Session s = HibernateUtil.getSessionFactory().openSession();

            Query q = s.createQuery("from Student");

            li = q.list();
            System.out.println("Student Get All Method ");
        } catch (Exception e) {
        }
        return li;
    }

    public static List<Student> getAllStudentsByDivid(Long div_id) {
        List<Student> li = null;
        try {
            Session s = HibernateUtil.getSessionFactory().openSession();
            Query q = s.createQuery("from Student where divid= " + div_id);
            li = q.list();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return li;
    }

    @Override
    public String toString() {
        return this.enrollmentno + " : " + this.fname;
    }

        
    

}
